package binarysearch;

/**
 * Created by JiaJia on 2019/5/28 0028.
 * Input: [3,4,5,1,2],
 * Output: 1
 */
public class MinimunInRotatedArray {
    public static int findMin(int[] nums){
        int l=0,h=nums.length-1;
        while (l<h){
            int mid=l+(h-l)/2;
            if (nums[mid]<=nums[h]){
                h=mid;
            }else {
                l=mid+1;
            }
        }
        return nums[l];
    }
    public static void main(String[] args) {
        int[] num1={3,4,5,1,2};
        int[] num2={8,9,1,2,3,4,5,6,7};
        System.out.println(findMin(num1));
        System.out.println(findMin(num2));
    }

}